﻿using System.Globalization;

namespace MaterialDesign3Demo.Domain;

public class FutureDateValidationRule : ValidationRule
{
    public override ValidationResult Validate(object value, CultureInfo cultureInfo)
    {
        DateTime time;
        if (!DateTime.TryParse((value ?? "").ToString(),
            CultureInfo.CurrentCulture,
            DateTimeStyles.AssumeLocal | DateTimeStyles.AllowWhiteSpaces,
            out time)) return new ValidationResult(false, "Invalid date");

        return time.Date <= DateTime.Now.Date
            ? new ValidationResult(false, "Future date required")
            : ValidationResult.ValidResult;
    }
}
